#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 305;
int n, s, ans = 0x3fffffff, e_cnt, d, l, r, heads[N], a[N][N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1099 树网的核.in", "r", stdin);
  freopen("P1099 树网的核.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &s);
  memset(a, 0x3f, sizeof(a));
  for (int i = 1, u, v, w; i <= n; ++i) {
    scanf("%d%d%d", &u, &v, &w);
    a[u][v] = w, a[v][u] = w;
  }
  for (int i = 1; i <= n; ++i) a[i][i] = 0;
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) a[i][j] = std::min(a[i][j], a[i][k] + a[k][j]);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i][j] != 0x3f3f3f3f && a[i][j] > d) {
        d = a[i][j];
        l = i, r = j;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[l][i] + a[i][r] == d) {
      for (int j = 1, ecc = -0x3f3f3f3f; j <= n; ++j) {
        ecc = -0x3f3f3f3f;
        if (a[l][j] + a[j][r] == d && a[i][j] <= s) {
          for (int k = 1; k <= n; ++k) {
            ecc = std::max(ecc, (a[i][k] + a[k][j] - a[i][j]) >> 1);
          }
          ans = std::min(ans, ecc);
        }
      }
    }
  }
  printf("%d", ans);
  return 0;
}